package com.gdwstudy.GenericExer;



import java.util.ArrayList;
import java.util.Comparator;

/**
 * @author 关道伟
 * @version 1.0
 */
public class TestGeneric {
    public static void main(String[] args) {
        ArrayList<Empolyee> empolyees = new ArrayList<>();
        empolyees.add(new Empolyee("GDW",50000,new Mydate(2000,10,10)));
        empolyees.add(new Empolyee("tom",15000,new Mydate(2001,11,24)));
        empolyees.add(new Empolyee("GDW",19000,new Mydate(2000,9,12)));
        System.out.println("=====list======");
        System.out.println(empolyees);
        System.out.println("==============定制排序后==========");
        empolyees.sort(new Comparator<Empolyee>() {
            @Override
            public int compare(Empolyee o1, Empolyee o2) {
                if(!(o1 instanceof Empolyee && o2 instanceof Empolyee)){
                    System.out.println("不是Employee类型无法比较\n");
                    return 0;
                }
                if(o1.getName().equals(o2.getName())){
                    //相同继续比较data
                    int i = o1.getBirthday().compareTo(o2.getBirthday());
                    return i;
                }else{
                    //不同直接返回结果
                    int i = o1.getName().compareTo(o2.getName());
                    return i;
                }
            }
        });
        System.out.println(empolyees);
    }
}
